#!/bin/bash

# Enrigin GStreamer 插件卸载脚本

set -e

GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m'

echo "=========================================="
echo "  Enrigin GStreamer 插件卸载"
echo "=========================================="
echo ""

# 检查是否为 root
if [ "$EUID" -ne 0 ]; then 
    echo -e "${RED}错误: 请使用 sudo 运行此脚本${NC}"
    exit 1
fi

# 检测架构
ARCH=$(uname -m)
if [ "$ARCH" == "aarch64" ]; then
    GST_PLUGIN_DIR="/usr/lib/aarch64-linux-gnu/gstreamer-1.0"
elif [ "$ARCH" == "x86_64" ]; then
    GST_PLUGIN_DIR="/usr/lib/x86_64-linux-gnu/gstreamer-1.0"
else
    echo -e "${RED}错误: 不支持的架构 $ARCH${NC}"
    exit 1
fi

echo "插件目录: $GST_PLUGIN_DIR"
echo ""

# 删除插件
if [ -f "$GST_PLUGIN_DIR/libgstenrigindec.so" ]; then
    echo "删除 enrigindec 插件..."
    rm -f "$GST_PLUGIN_DIR/libgstenrigindec.so"
    echo -e "${GREEN}✓ enrigindec 已删除${NC}"
else
    echo -e "${YELLOW}⚠ enrigindec 插件不存在${NC}"
fi

if [ -f "$GST_PLUGIN_DIR/libgstenriginenc.so" ]; then
    echo "删除 enriginenc 插件..."
    rm -f "$GST_PLUGIN_DIR/libgstenriginenc.so"
    echo -e "${GREEN}✓ enriginenc 已删除${NC}"
else
    echo -e "${YELLOW}⚠ enriginenc 插件不存在${NC}"
fi

echo ""
echo -e "${GREEN}✓ 卸载完成${NC}"
echo ""

# 验证卸载
if gst-inspect-1.0 enrigindec > /dev/null 2>&1; then
    echo -e "${RED}✗ enrigindec 仍然存在${NC}"
else
    echo -e "${GREEN}✓ enrigindec 已完全移除${NC}"
fi

if gst-inspect-1.0 enriginenc > /dev/null 2>&1; then
    echo -e "${RED}✗ enriginenc 仍然存在${NC}"
else
    echo -e "${GREEN}✓ enriginenc 已完全移除${NC}"
fi

echo ""
